﻿using DEL.Webmonitor;
using IDAL.Webmonitor;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;

namespace DAL.Webmonitor
{
    public class InfoHitRepository : BaseRepository<InfoHit> ,IInfoHitRepository  //数据库访问层的设计思路是：先继承基类，在实现接口。
    {
        //在EF Core我们可以直接通过底层的ADO.NET来进行查询
        public IEnumerable<string> GetAllUrl()
        {
            List<string> list = new List<string>();
            using (var connection = _context.Database.GetDbConnection())
            {
                connection.Open();

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "SELECT Url FROM Webm_InfoHit ORDER BY Id DESC";

                    using (SqlDataReader reader = command.ExecuteReader() as SqlDataReader)
                    {
                        while (reader.Read())
                        {
                            list.Add(Convert.ToString(reader["Url"]));
                        }
                    }
                }
            }
            return list;
        }
        
    }
}
